package com.iqismart.shorturl.schedule;

import com.iqismart.shorturl.service.UserService;
import com.iqismart.shorturl.vo.RegisterRequest;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Auther sty
 * @createTime 2019-10-24 10:22
 */
@Component
public class NewUserSchedule {

    @Autowired
    private UserService userService;


    @Scheduled(fixedDelay = 1000L * 60)
    public void randomOnlineUser(){
        if(register()){
            final RegisterRequest request = new RegisterRequest();
            request.setUsername(getUserName());
            request.setPassword("1111");
            request.setPasswordConfirm("1111");
            userService.register(request);

        }
    }


    public boolean register(){
        int random =Double.valueOf(Math.random()*1000 + 1).intValue();
        if(random < 700 ){
            return true;
        }
        return false;
    }

    public String getUserName(){
        return RandomStringUtils.random(10);
    }

}
